﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EmotionRecognitionEntities;
using EmotionRecognitionManager;
using EmotionRecognitionDB;

namespace EmotionRecognitionMessages
{
    public class Messages
    {
        public Messages() {}

        public ReplyMsg GetChunkslables()
        {

            return DBQueries.GetChunks();

        }

        //this method will activated when Accept Emotion button is pressed
        public void AcceptEmotion(int chunkId, Picture picture, int userID)
        {
            InitialEndowment intial = new InitialEndowment();
            intial.AcceptEmotion(chunkId, picture, userID);
                
        }

        public ReplyMsg CreateNewPicutreInDB(string fileName)
        {
            return DBQueries.CreateNewPicutreInDB(fileName);

        }
        public ReplyMsg CreateNewPicutreInDB(string fileName, int sysVar)
        {
            return DBQueries.CreateNewPicutreInDB(fileName, sysVar);

        }

        public ReplyMsg LoadPicutersFromDB( int LoadReviewPictures)
        {
            return DBQueries.LoadPicutersFromDB(LoadReviewPictures);
        }

        public ReplyMsg GetLastPictureID()
        {
            return DBQueries.GetLastPictureID();

        }

        public ReplyMsg GetallAu()
        {
           return DBQueries.GetAllAus();

        }
        public ReplyMsg RefinementMsg(int initCentersSelection, double alpha, double diffEndIter, bool ispheeDist, bool isHammingInt, double disposeCaseWeightDist)

        {
            Refinement refine = new Refinement(initCentersSelection, alpha, diffEndIter, ispheeDist, isHammingInt, disposeCaseWeightDist);
            refine.ExecuteRefinementAlgoritm();
            return new ReplyMsg(true);
        }
        public ReplyMsg AddAutoPictureinDB(Picture pic)
        {
            //
            return DBQueries.AddAusToPictureInDB(pic);
        }

        public ReplyMsg CreateNewChunk(string label)
        {

            return DBQueries.CreateNewChunk(label);
        }

        public ReplyMsg UpdateHasAUs(int pictureID,bool HasAUs)
        {
             return DBQueries.UpdateHasAu(pictureID, HasAUs);
        }

        public void UpdatePicturesinDB()
        {

            //need implemention

        }

        public void SetIndexCase(bool secondRun)
        {

            DBQueries.SetIndexCases(secondRun);
        }
        ////////////
        public ReplyMsg RegisterUser(string Password, string name, bool role)
        {
            UserProperties user = new UserProperties(Password, name, role);
            return DBQueries.RegisterationRequest(user);
        }

        //////////////
        public ReplyMsg ExecuteRetrievalAlgorithm(List<int> inputauList)
        {
            Retrieval retrieval = new Retrieval();
            return retrieval.ExecuteRetrievalAlgoritm(inputauList);
        }
        ///////////
        public ReplyMsg SaveImage(System.Drawing.Image image, string savePath, string name)
        {
            return Utilities.SaveImageCapture(image, savePath,name);
        }
        ///////////
        public ReplyMsg CheckIfExist(string userFeedBack)
        {
            return DBQueries.CheckIfExist(userFeedBack);
        }

        public ReplyMsg ExecuteAdaptation(Dictionary<Chunk, Case> solutions, string chunkFeedback, bool secondRun)
        {
            Adaptation adapt = new Adaptation();
            return adapt.ExecuteAdaptationAlgorithm(solutions, chunkFeedback, secondRun);
        }

        public ReplyMsg LoginAuthentication(string Password, string name)
        {
            UserProperties user = new UserProperties(Password, name);
            return DBQueries.LoginRequest(user);
        }

        public ReplyMsg GetChunkByLabel(string p)
        {
            return DBQueries.CheckIfChunkExists(p);
        }

        public ReplyMsg copyFile(string sourcePath, string targetPath, string newFileName)
        {
            return Utilities.CopyFile(sourcePath, targetPath, newFileName);
        }

        public ReplyMsg getExternalImageName()
        {
            return DBQueries.getExternalImageName();
        }

        public ReplyMsg GetEnvironmentPath(int sysVar)
        {
            return DBQueries.returnSysVarPath(sysVar);
        }


        public ReplyMsg OpenFile(string fileName, string  path)
        {
            return Utilities.OpenFile( fileName,  path);
        }
        
       
        public ReplyMsg GetretrievalCorrectAnswer()
        {

            return Statistics.GetretrievalCorrectAnswer();
        }

        public ReplyMsg UpdateStatisticsManager(StatisticsType statisticsType, FeedBackType feedbackType)
        {
            return Statistics.UpdateStatisticsManager(statisticsType, feedbackType);
        }

        public ReplyMsg ResetStatistics(StatisticsType statisticsType)
        {
            return Statistics.ResetVariables(statisticsType);

        }

    }
}
